package com.gouzheng.controller;

import com.gouzheng.service.PhoneService;
import com.gouzheng.util.Jsonres;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class phoneController {

    @Autowired
    private PhoneService phoneService;

   /*
   *发送验证码
   * @Param phone
   * @Param session
   * @return
   * */
   @RequestMapping(value="/phoneLogin",method = RequestMethod.GET)
   @ResponseBody
   public Jsonres phoneMessage(String phone, HttpSession session){
       Boolean aBoolean=phoneService.selectPhone(phone,session);
       if(aBoolean){
           return new Jsonres("200","验证码发送成功");
       }
       return  new Jsonres("500","手机号绑定用户或号码不正确");

   }

    /*
     * 验证码登录
     * @Param phone
     * @Param session
     * @return
     * */
    @RequestMapping(value = "/phoneLogin",method = RequestMethod.POST)
    @ResponseBody
    public Jsonres phoneLogin(String massage,HttpSession session){
        Boolean aBoolean=phoneService.phoneLogin(massage,session);
        if(!aBoolean){
            return new Jsonres("500","验证码不正确");
        }
            return new Jsonres("200","登陆成功");
    }

}
